﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MoroMoro.Samples.ToDoList.Base.Application;
using MoroMoro.Samples.ToDoList.Application;
using MoroMoro.Samples.ToDoList.Application.ToDos;
using MoroMoro.Samples.ToDoList.Domain.ToDos;
using MoroMoro.Samples.ToDoList.Domain.Categories;
using MoroMoro.Samples.ToDoList.Presentation.Views.ToDos;
using MoroMoro.Samples.ToDoList.Presentation.ErrorMessages.ToDos;

namespace MoroMoro.Samples.ToDoList.Presentation.Presenters.ToDos
{
    /// <summary>
    /// ToDo 作成プレゼンターです。
    /// </summary>
    public sealed class ToDoCreationPresenter : ToDoBuildPresenter<IToDoCreationView, ToDoCreationErrors>
    {
        /// <summary>
        /// <see cref="ToDoCreationPresenter"/> クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="view">ビュー。</param>
        /// <param name="facade">ファサード。</param>
        /// <exception cref="System.ArgumentNullException">view または facade が null です。</exception>
        public ToDoCreationPresenter(IToDoCreationView view, ToDoListFacade facade)
            : base(view, facade, facade.CreateToDoBuilder())
        {
        }


        /// <inheritdoc/>
        protected override void OnLoad(object sender, EventArgs e)
        {
            base.OnLoad(sender, e);

            View.Category = Facade.CategoryFilter;
        }

        /// <inheritdoc/>
        protected override void ExecuteBuild(Action<ToDoCreationErrors> errorHandler)
        {
            Facade.ExecuteToDoCreation(Builder, errorHandler);
        }

        /// <inheritdoc/>
        protected override string CreateErrorMessage(ToDoCreationErrors error)
        {
            var errorMessage = new ToDoCreationErrorMessage();
            error.HandledBy(errorMessage);
            return errorMessage.ToString();
        }
    }
}
